package view;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import controller.Sistema;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AltaServicioDatos extends javax.swing.JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private AltaServicioDatos instancia;
	private JLabel Unidad;
	private JButton Cancelar;
	private JButton Aceptar;
	private JTextField jTextField3;
	private JTextField jTextField2;
	private JTextField jTextField1;
	private JLabel Precio;
	private JLabel Nombre;
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				AltaServicioDatos inst = new AltaServicioDatos();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public AltaServicioDatos() {
		super();
		initGUI();
		instancia=this;
		this.setTitle("Alta Servicios Datos");
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				Nombre = new JLabel();
				getContentPane().add(Nombre);
				Nombre.setText("Nombre");
				Nombre.setBounds(32, 27, 129, 16);
			}
			{
				Unidad = new JLabel();
				getContentPane().add(Unidad);
				Unidad.setText("Unidad");
				Unidad.setBounds(32, 70, 129, 16);
			}
			{
				Precio = new JLabel();
				getContentPane().add(Precio);
				Precio.setText("Precio");
				Precio.setBounds(33, 115, 128, 16);
			}
			{
				jTextField1 = new JTextField();
				getContentPane().add(jTextField1);
				jTextField1.setBounds(195, 27, 131, 23);
			}
			{
				jTextField2 = new JTextField();
				getContentPane().add(jTextField2);
				jTextField2.setBounds(195, 67, 131, 23);
			}
			{
				jTextField3 = new JTextField();
				getContentPane().add(jTextField3);
				jTextField3.setBounds(195, 112, 131, 23);
			}
			{
				Aceptar = new JButton();
				getContentPane().add(Aceptar);
				Aceptar.setText("Aceptar");
				Aceptar.setBounds(71, 178, 85, 24);
				Aceptar.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
						if (HelperTest.validarServicio(jTextField1.getText(), jTextField2.getText(), Float.parseFloat(jTextField3.getText() ))) {
							if  (Sistema.getInstance().altaServicioDatos(jTextField1.getText(), jTextField2.getText(), Float.parseFloat(jTextField3.getText())) ==false){
								HelperTest.showMessage("No se pudo dar de alta el servicio");
							}
							limpiarCampos();	
						}
						
						
					}
				});
			}
			{
				Cancelar = new JButton();
				getContentPane().add(Cancelar);
				Cancelar.setText("Cancelar");
				Cancelar.setBounds(195, 178, 85, 24);
				Cancelar.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
						Menu app = new Menu();
						app.setLocationRelativeTo(null);
						app.setVisible(true);
						instancia.dispose();
						
					}

					
				});
			}
			pack();
			this.setSize(400, 277);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	private void limpiarCampos() {
		jTextField1.setText("");
		jTextField2.setText("");
		jTextField3.setText("");
	
		
	}

}
